//
//  ImageDemo.m
//  Exercise
//
//  Created by zhouxiaobo on 15/11/12.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "ImageDemo.h"

@implementation ImageDemo

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1. 图片的切换,通过highlighted这个属性来获取highlightedImage指定的图片
    _imageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"weibo-up"] highlightedImage:[UIImage imageNamed:@"weibo-down"]];
    _imageView1.highlighted = YES;
    _imageView1.frame = CGRectMake(screenWidth/2-50, 200, 100, 100);
    
    [self.view addSubview:_imageView1];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(screenWidth/2-50, 450, 100, 50);
    btn.backgroundColor = [UIColor yellowColor];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn setTitle:@"换样式" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(changeImgStyle) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    //2. 图片上的按钮无法点击,必须把userInteractionEnabled属性设置为YES,UIView的基类都是YES,但到了UIImageView把它改成了NO
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(screenWidth/2-100, 0, 200, 200)];
    imageView2.image = [UIImage imageNamed:@"1"];
    imageView2.userInteractionEnabled = YES;
    [self.view addSubview:imageView2];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn2.frame = CGRectMake(200/2-30, 35, 60, 20);
    btn2.backgroundColor = [UIColor yellowColor];
    [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn2 setTitle:@"不能点" forState:UIControlStateNormal];
    [imageView2 addSubview:btn2];
}

- (void)changeImgStyle {
    if (_imageView1.highlighted) {
        _imageView1.highlighted = NO;
    }else{
        _imageView1.highlighted = YES;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
